package cn.edu.lcu.cs.javalearning.dao;

import java.util.List;

import cn.edu.lcu.cs.javalearning.model.Student;

public class StudentDaoImpl extends BaseDaoImpl<Student, Long> implements StudentDao {

    public StudentDaoImpl() {
	super(Student.class);
    }

    @Override
    public Student findByStudentNo(String studentNo) {
	String sql = "select * from student where student_no = ?";
	List<Student> list = query(sql, studentNo);
	if (list != null && list.size() > 0) {
	    return list.get(0);
	}
	return null;
    }

    @Override
    public List<Student> findByStudentName(String studentName) {
	String sql = "select * from student where student_name = ?";
	return query(sql, studentName);
    }

    @Override
    public List<Student> findAllStudentNoAndStudentName() {
	String sql = "select student_name, student_no from student";
	return query(sql, null);
    }

    @Override
    public Long countByStudentName(String studentName) {
	String sql = "select count(*) from student where student_name = ?";
	return (Long) queryScalar(sql, studentName);
    }
}
